
/* a forma de envio de dados da fun��o usando form simplifica o c�digo
   pois n�o � necess�rio o uso de vari�veis auxiliares*/
function Validar(form) 
{
    if(form.nome.value=='')
    {
        document.getElementById('nome').style.borderColor = "red";
        document.getElementById('result_nome').innerHTML = '<font color = "red">Escreva seu nome</font>';
        return false;
    }
    else
    {
        document.getElementById('nome').style.borderColor = "";
        document.getElementById('result_nome').innerHTML = ' ';
    }		
    if(validar_email() == false)
    {	
        document.getElementById('email').style.borderColor = "red";
        document.getElementById('result_email').innerHTML = '<font color="red">E-mail invalido</red>';
        return false;
    }
    else
    {
        document.getElementById('email').style.borderColor = "";
        document.getElementById('result_email').innerHTML = ' ';
    }	

    if(form.login.value=='')
    {
        document.getElementById('login').style.borderColor = "red";
        document.getElementById('result_login').innerHTML = '<font color = "red">Login nao pode estar em branco</font>';
        return false;

    }
    else
    {
        document.getElementById('login').style.borderColor = "";
        document.getElementById('result_login').innerHTML = ' ';
    }	
    if(form.senha.value=='' || form.csenha.value=='')
    {
        document.getElementById('senha').style.borderColor = "red";
        document.getElementById('csenha').style.borderColor = "red";
        document.getElementById('result_senha').innerHTML = '<font color = "red">Campo obrigatorio</font>';
        return false;

    }
    else if(form.senha.value != form.csenha.value)
    {
        document.getElementById('result_senha').innerHTML = '<font color = "red">A senha e a confirmacao estao diferentes</font>';
        return false;
    }
    else
    {
        document.getElementById('senha').style.borderColor = "";
        document.getElementById('result_senha').innerHTML = ' ';
    }
		
    return true;	
}

function validar_email()
{
    var eml = document.getElementById('email').value;
    var elem = document.getElementById('result');
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);

    if(er.test(eml))
        return true;
    else
        return false;
        
}

function checar_senhas()
{
    var senha = document.getElementById('senha').value;
    var csenha = document.getElementById('csenha').value;

    if(senha != csenha)
    {
        document.getElementById('csenha').style.border="solid 1px red";
    }
    else
    {
        document.getElementById('csenha').style.border="solid 1px green";
    }
}